Dataviz with R

Ilya Kashnitsky

28 January 2019

We are doing the right thing here

Anscombe’s Quartet

Imgur

dino https://www.autodeskresearch.com/publications/samestats

Outline

Day 1: tydyverse, ggplot2

  • dataviz examples
  • tidy data
  • data wrangling practice
  • ggplot2
  • ggplot2 practice

Day 2: maps in R

Examples of data visualization

https://jschoeley.shinyapps.io/hmdexp

http://bancdadesced.uab.es/population_change/

http://www.global-migration.info

https://ikashnitsky.github.io/2018/the-lancet-paper/

More

Tidyverse

The most influential R developer

Hadley Wickham

hadley

tidyverse

https://blog.rstudio.org/2016/09/15/tidyverse-1-0-0/

https://www.tidyverse.org/

tidy data

Wickham, H. (2014). Tidy Data. Journal of Statistical Software, 59(10). Retrieved from http://www.jstatsoft.org/v59/i10

Tidy data is a standard way of mapping the meaning of a dataset to its structure.

A dataset is messy or tidy depending on how rows, columns and tables are matched up with observations, variables and types.

In tidy data:

  1. Each variable forms a column.
  2. Each observation forms a row.
  3. Each type of observational unit forms a table.

Examples and exercises

Please follow me on the R script "examples-tidyverse.R"

Visualizing data with ggplot2

A bit more motivation

http://qz.com/316906/the-dude-map-how-american-men-refer-to-their-bros

https://www.granvillematheson.com/post/self-portrait/

https://fivethirtyeight.com/features/why-the-oldest-person-in-the-world-keeps-dying/

https://barcanumbers.wordpress.com/2018/12/06/who-are-the-best-finishers-in-contemporary-football/

More

Plotting systems in R?

  • base
  • lattice
  • ggplot2

“The winner takes it all”

cat

Strength of base plotting system

  • Usually, base knows how to plot an object
  • Extremely easy to use if you are happy with the default settings
  • BUT
  • Now ggplot2 has the autoplot function

The only example when ggplot2 failed for me

http://stackoverflow.com/questions/17753502

https://github.com/tidyverse/ggplot2/issues/1720

What makes ggplot2 special?

“gg” means “Grammar of graphics”

http://www.springer.com/us/book/9780387245447

Extremely big and helpful community

  • Help
  • Examples
  • Rapid development
  • Extensions

http://www.ggplot2-exts.org/gallery/

Amazing documentation

http://docs.ggplot2.org/current

ggplot2 show

Please follow me on “examples-ggplot2.R

The most powerful and underrated type of plot

Dotplot

http://www.b-eye-network.com/view/2468

http://demographer.com/dsitl/08-cleveland-dot-plots/

https://link.springer.com/article/10.1007%2Fs10708-018-9953-5#Fig2

You are welcome to replicate this plot using “replicate-dotplot-figure.R

Further reading coding

https://ikashnitsky.github.io/2017/data-acquisition-one/

https://serialmentor.com/dataviz/

http://socviz.co/index.html

One last hint

https://github.com/dreamRs/esquisse